<!--
 * @Author: your name
 * @Date: 2022-02-09 21:33:39
 * @LastEditTime: 2022-02-15 19:53:44
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \code\09.组件实例三大属性之refs\03.createRef形式的ref.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03.createRef形式的ref</title>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="../js/prop-types.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        class DemoComponent extends React.Component {
            container1 = React.createRef() // 创建一个容器，用于存放真实 DOM
            container2  = React.createRef() // 创建一个容器，用于存放真实 DOM
            alertMessage = () => {
                console.log(this.container1)
                alert(this.container1.current.value)
            }

            alertMessageOnBlur = () => {
                alert(this.container2.current.value)
            }
            render(){
                console.log(this)
                return (
                    <div>
                        <input type="text" ref={this.container1}/>
                        <button onClick={this.alertMessage}>Click this to alert message before</button>
                        <input type="text" placeholder='Alert message when out of focus' onBlur = {this.alertMessageOnBlur} ref={this.container2}/>
                    </div>
                )
            }
        }

        ReactDOM.render(<DemoComponent/>, document.querySelector('#app'))
    </script>
</body>
</html>